//
//  HBJRoundedImageVIew.m
//  meiyinxiang
//
//  Created by apple on 2018/1/19.
//  Copyright © 2018年 hbjApple. All rights reserved.
//

#import "HBJRoundedImageVIew.h"
@interface HBJRoundedImageVIew()
@property (nonatomic,copy) UIImage *roundImage;
@end
@implementation HBJRoundedImageVIew
- (void)addMaskToBounds:(CGRect)maskBounds{
    CGFloat w = maskBounds.size.width;
    CGFloat h = maskBounds.size.height;
    CGSize size = maskBounds.size;
    CGFloat scale = [UIScreen mainScreen].scale;
    CGRect imgeRect = CGRectMake(0, 0, w, h);
    if (self.cornerRadius < 0) {
        self.cornerRadius = 0;
    }else if (self.cornerRadius > MIN(w, h)){
        self.cornerRadius = MIN(w, h)/2;
    }
    UIImage *image = self.image;
    UIGraphicsBeginImageContextWithOptions(size, NO, scale);
    [[UIBezierPath bezierPathWithRoundedRect:imgeRect cornerRadius:self.cornerRadius] addClip];
    [image drawInRect:imgeRect];
    self.roundImage = UIGraphicsGetImageFromCurrentImageContext();
    self.image = self.roundImage;
    UIGraphicsEndImageContext();
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
